#include "stdafx.h"

leveldb::DB* Global::g_db = NULL;
bool Global::initDB()
{
	leveldb::Options op;
	op.create_if_missing = true;
	leveldb::Status staus = leveldb::DB::Open(op, "demo.db", &g_db);
	if (!staus.ok())
		return false;
	return true;
}

void Global::stopDB()
{
	if (g_db == NULL)
		return;
	delete g_db;
	g_db = NULL;
}

void Global::Get_Value(const char* key, std::string& s)
{
	if (g_db == NULL)
		return;
	leveldb::Status status = g_db->Get(leveldb::ReadOptions(), key, &s);
	//assert(status.ok());
}

void Global::Put_Value(const char* key, CWriterStream& s)
{
	if (g_db == NULL)
		return;
	leveldb::Slice value(s.c_str(), s.length());
	leveldb::Status status = g_db->Put(leveldb::WriteOptions(), key, value);
	assert(status.ok());
	s.clear();
}

void Global::loadData()
{
	g_accountManager->loadData();
}

void Global::savaData()
{
	g_accountManager->saveData();
}


